package ma.ensao.evalmetrics.view;
import java.io.File;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import ma.ensao.evalmetrics.controller.FileManager;
import ma.ensao.evalmetrics.model.MyFile;
import ma.ensao.evalmetrics.model.User;
/*
* Operations sur les files(Tester, Supprimer, Uploader)
*/
public class FileAction extends ActionSupport implements SessionAware{
	  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private File myFichier;
	   private String myFichierContentType;
	   private String myFichierFileName;
	private MyFile myFile;
	private List<MyFile> fileList;
	private List<User> userList;
	private Long id;
    private FileManager projet;
    private List<Long> users;
	private List<Long> users_chosen;

	private Map<String, Object> session;

    public FileAction() {
		projet = new FileManager();
	}

	public String execute() {
		System.out.println("001"+getMyFile());
		return SUCCESS;
	}
	public String fileUpload() {	  
		projet.upload(myFile, users_chosen);
		return SUCCESS;
	}


	public String testerprojet() {
		System.out.println(getId());
		myFile=projet.testerprojet(getId());
		return SUCCESS;
	}
	public String delete() {
		System.out.println(getId());
		projet.delete(getId());
		return SUCCESS;
	}
	
	public MyFile getMyFile() {
		return myFile;
	}
	public List<MyFile> getFileList() {
		return fileList;
	}
	public Long getId() {
		return id;
	}
	public FileManager getProject() {
		return projet;
	}
	public void setFileList(List<MyFile> fileList) {
		this.fileList = fileList;
	}
	public void setMyFile(MyFile myFile) {
		this.myFile = myFile;
	}
	public void setId(Long id) {
		this.id = id;
	}
	//uploadaction
	 public File getMyFichier() {
	      return myFichier;
	   }
	   public void setMyFichier(File myFichier) {
	      this.myFichier = myFichier;
	   }
	   public String getMyFichierContentType() {
	      return myFichierContentType;
	   }
	   public void setMyFichierContentType(String myFichierContentType) {
	      this.myFichierContentType = myFichierContentType;
	   }
	   public String getMyFichierFileName() {
	      return myFichierFileName;
	   }
	   public void setMyFichierFileName(String myFichierFileName) {
	      this.myFichierFileName = myFichierFileName;
	   }

	public List<Long> getUsers() {
		return users;
	}

	public void setUsers(List<Long> users) {
		this.users = users;
	}

	public FileManager getProjet() {
		return projet;
	}

	public void setProjet(FileManager projet) {
		this.projet = projet;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public List<Long> getUsers_chosen() {
		return users_chosen;
	}

	public void setUsers_chosen(List<Long> users_chosen) {
		this.users_chosen = users_chosen;
	}
}
